package com.md.value.enums;

import com.md.base.EnumBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * 2023-08-08 17:56
 */
@Getter
@AllArgsConstructor
public enum DictionaryEnum implements EnumBase {

  /**
   * 角色id
   */
  ROLE_ID(0, "ROLE_ID"),
  /**
   * 验证码长度
   */
  CODE_LENGTH(1, "CODE_LENGTH"),
  /**
   * 验证码有效期
   */
  CODE_EFFECTIVE_TIME(2, "CODE_EFFECTIVE_TIME");

  static final Map<Integer, DictionaryEnum> ENUM_MAP = Arrays.stream(DictionaryEnum.values())
    .collect(Collectors.toMap(EnumBase::getCode, e -> e));
  static final Map<String, DictionaryEnum> ENUM_MAP_STRING = Arrays.stream(DictionaryEnum.values())
    .collect(Collectors.toMap(EnumBase::getMessage, e -> e));
  private final Integer code;
  private final String message;

  public static DictionaryEnum of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }

  public static DictionaryEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }

}
